import Router from 'vue-router'
import Http from '../../../components/http'
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator'
import TcBanner from '@/controls/TcBanner.vue'
import TcImage from '@/controls/TcImage.vue'
import TcBarCard from '@/controls/TcBarCard.vue'
import TcPollCard from '@/controls/TcPollCard.vue'
import TcCardList from '@/controls/TcCardList.vue'
import TcScrollView from '@/controls/TcScrollView.vue'

const decline = '#25D282'
const rise = '#FB4B55' // 升
const unchange = '##464646'

@Component({
  components: {
    TcImage,
    TcBanner,
    TcPollCard,
    TcBarCard,
    TcCardList,
    TcScrollView
  }
})
export default class HomePage extends Vue {
  height = '100%'

  listImg = [
    { img: './static/images/banner1.png', url: '/view/11' },
    { img: './static/images/banner2.png', url: '/view/12' },
    { img: './static/images/banner3.png', url: '/view/13' }
  ]

  barList = [
    { name: '关于点金', icon: 'crown' },
    { name: '新手学堂', icon: 'hat' },
    { name: '财经资讯', icon: 'news' },
    { name: '签到有礼', icon: 'sign' }
  ]

  newsList = []

  pollList = [
    { name: '点金黄金', title: '267.03', value: '+0.09 / +0.57%', color: decline },
    { name: '点金白银', title: '3.435', value: '+0.09 / +0.57%', color: rise },
    { name: '点金铂金', title: '198.0', value: '+0.09 / +0.57%', color: rise },
    { name: '点金钯金', title: '224.9', value: '+0.09 / +0.57%', color: rise }
  ]

  newsTitle = '独家精选'

  mounted () {
    this.height = window.innerHeight + 'px'
    if (window.cordova) {
      StatusBar.styleLightContent()
    }
    Http.get(Http.Urls.getNewsList).then(function (list) {
      this.newsList = list
    }.bind(this))
  }

  barClick (index) {
    switch (this.barList[index].icon) {
      case 'crown':
        this.$router.push('/view/1')
        break
      case 'hat':
        this.$router.push('/view/2')
        break
      case 'news':
        this.$router.push('/information/view')
        break
      case 'sign':
        this.$router.push('/view/3')
        break
      default:
        break
    }
  }

  newsClick (index) {
    this.$router.push('/view/' + index)
  }

  onInfinite (done) {
    Http.get(Http.Urls.getNewsList).then(function (list) {
      list.forEach(element => {
        this.newsList.push(element)
      })
      done()
    }.bind(this))
  }

  onJumpClick (url) {
    this.$router.push(url)
  }

}
